package com.qingcheng.controller;


import com.qingcheng.pojo.goods.Brand;
import com.qingcheng.service.goods.BrandService;
import com.qingcheng.entity.PageResult;
import com.qingcheng.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    //查找所有
    @GetMapping("/findAll")
    public List<Brand> findAll(){
       return brandService.findAll();
    }

    //分页查找
    @GetMapping("/findPage")
    public Result findPage(int page, int size){
        Result result = brandService.findPage(page, size);
        return result;
    }

    @PostMapping("/findList")
    public List<Brand> findList(@RequestBody Map<String,Object> searchMap){
        return  null;
    }

    @PostMapping("/findPage")
    public Result findPage(@RequestBody Map<String,Object> searchMap,int page, int size){
        Result result = brandService.searchPage(searchMap,page,size);
        return result;
    }

    @GetMapping("/findById")
    public Brand findById(Integer id){
        Brand brand = brandService.getById(id);
        return brand;
    }


    @PostMapping("/add")
    public Result add(@RequestBody Brand brand){
        brandService.add(brand);
        return new Result(0,true,"添加成功");
    }

    @PostMapping("/update")
    public Result update(@RequestBody Brand brand){
         Result r = brandService.updateBy(brand);
         return r;
     }


    @GetMapping("/delete")
    public Result delete(Integer id){
        Result r = brandService.deleteBy(id);
        return r;
    }

}
